<?php

    /* Input : XX-XX-X-XXX-001*/

    $nuptk = $_SESSION["SES_USERNAME"];
    $data=$_GET["q"];
    $sprop2 = $_GET["prop"];
    $skab = $_GET["kab"];
    $ikab2 = (int)$skab;
    $iprop_sel= (int)$sprop2;
    $reg_anggota = $_GET["anggota"];
    $tipe_kk = $_GET["tipe_kk"];
    $skec = $_GET["kec"];
    $sdaerah = $_GET["daerah"];
    include('class.mysql.php');
    $mydb = new mysql();
    $connection = $mydb->Connect();
    if(1)
    {
	$stTemp = '<table class="box" align="center" id="data_table">'.'<tbody><tr>'.'<th rowspan="2">Nama Kelompok Kerja</th>'.'<th colspan="12">Ringkasan Data Kelompok Kerja</th>'.'</tr><tr>';
	$stTemp .= '<th>No Registrasi</th>';
	if($_COOKIE["ck_cc2"]=="on" | $_COOKIE["ck_cc2"]=="")
		$stTemp .= '<th>Propinsi</th>';
	if($_COOKIE["ck_cc3"]=="on" | $_COOKIE["ck_cc3"]=="")
		$stTemp .= '<th>Kab / Kota</th>';
	if($_COOKIE["ck_cc4"]=="on" | $_COOKIE["ck_cc4"]=="")
		$stTemp .= '<th>Jenis KK</th>';
	if($_COOKIE["ck_cc5"]=="on" | $_COOKIE["ck_cc5"]=="")
		$stTemp .= '<th>Kecamatan</th>';
	if($_COOKIE["ck_cc6"]=="on" | $_COOKIE["ck_cc6"]=="")
		$stTemp .= '<th>Jumlah Anggota</th>';
	if($_COOKIE["ck_cc7"]=="on" | $_COOKIE["ck_cc7"]=="")
		$stTemp .= '<th>Nomor HP</th>';
	if($_COOKIE["ck_cc8"]=="on" | $_COOKIE["ck_cc8"]=="")
		$stTemp .= '<th>Alamat Email</th>';
	if($_COOKIE["ck_cc9"]=="on" | $_COOKIE["ck_cc9"]=="")
		$stTemp .= '<th>Nama Bank</th>';
	if($_COOKIE["ck_cc10"]=="on" | $_COOKIE["ck_cc10"]=="")
		$stTemp .= '<th>No Rekening</th>';
	if($_COOKIE["ck_cc11"]=="on" | $_COOKIE["ck_cc11"]=="")
		$stTemp .= '<th>Atas Nama</th></tr>';
	$stTemp .= '<input name="checkboxnull" type="checkbox" style="display:none;" />';
	$sql="SELECT nama_kk,no_reg,kecamatan,nama_bank,rek_bank,pemilik_rek,email,hp FROM identitas WHERE mid(no_reg,7,1) like '$tipe_kk%' and mid(no_reg,1,2) = '$sprop2' and mid(no_reg,4,2) like '$skab%' and kecamatan like '$skec%' and daerah like '$sdaerah%' order by mid(no_reg,1,5),mid(no_reg,13,3)";
	//echo "$sql";	
	$query = $mydb->Query($sql);
	$num = $mydb->FetchNum($query);
	
	//$kabupaten[]="Pilih kota2";
	$urut=1;
	while($array= mysql_fetch_row($query))
	{
	    $nama_kk2=$array[0];
	    if($nama_kk2=="")
	        $nama_kk2='-';
	    $no_reg2=$array[1];
	    if($no_reg2=="")
	        $no_reg2='-';
	    $kecamatan2=$array[2];
	    if($kecamatan2=="")
	        $kecamatan2='-';
	    $nama_bank = $array[3];
	    if($nama_bank=="")
	        $nama_bank='-';
	    $no_rek_bank = $array[4];
	    if($no_rek_bank=="")
	        $no_rek_bank='-';
	    $rek_atas_nama = $array[5];
	    if($rek_atas_nama=="")
	        $rek_atas_nama='-';
	    $email = $array[6];
	    if($email=="")
	        $email='-';
	    $hp = $array[7];
	    if($hp=="")
	        $hp='-';
	    /*Mengambil nama propinsi*/
            $sprop = substr($no_reg2,0,2);
            $skab2 = substr($no_reg2,3,2);
            $sql2="SELECT propinsi FROM propinsi where kode='$sprop'";
            //echo "$sql2";	
            $query2 = $mydb->Query($sql2);
            $num2 = $mydb->FetchNum($query2);
            if($array2= mysql_fetch_row($query2))
            {
	         $nama_prop=$array2[0];
            }
	    //menghitung jumlah anggota kelompok kerja	
	    $sql2="SELECT COUNT(*) FROM anggota WHERE no_reg= '$no_reg2'";
	    //echo "$sql";	
	    $query2 = $mydb->Query($sql2);
	    $num2 = $mydb->FetchNum($query2);
	    //$kabupaten[]="Pilih kota2";
	    if($array2= mysql_fetch_row($query2))
	    {
		$jumlah_anggota = $array2[0];
	    }
            
            //end
	    /*Mengambil nama kabupaten*/
            $sprop = substr($no_reg2,0,2);
            $skab2 = substr($no_reg2,3,2);
            $sql2="SELECT kabupaten FROM kabupaten where kode_prop = '$sprop' and kode='$skab2'";
            //echo "$sql2";	
            $query2 = $mydb->Query($sql2);
            $num2 = $mydb->FetchNum($query2);
            if($array2= mysql_fetch_row($query2))
            {
	         $nama_kab=$array2[0];
            }
            //end
            
	    if (substr($no_reg2,6,1)=='1')
		$jenis_kk='KKG';
	    else if (substr($no_reg2,6,1)=='2')
	        $jenis_kk ='MGMP';
	    else if (substr($no_reg2,6,1)=='3')
	        $jenis_kk ='KKKS';
	    else if (substr($no_reg2,6,1)=='4')
	        $jenis_kk ='MKKS';
	    else if (substr($no_reg2,6,1)=='5')
	        $jenis_kk ='KKPS';
	    else if (substr($no_reg2,6,1)=='6')
	        $jenis_kk ='MKPS';
	    //echo substr($no_reg2,6,1);
	    $ln_tampil='view.php?reg='.$no_reg2;
            $kecawal=strtoupper(substr($kecamatan2,0,1));
            $kecsisa=strtolower(substr($kecamatan2,1,20));
            $kecamatan2=$kecawal.$kecsisa;	    
	    $stTemp .= '<tr><td nowrap=""><input type="checkbox" name="option_table[]" value="" checked="true"><span style="color:white">_</span><a href='.$ln_tampil.'>'.(string)$urut.' - '.$nama_kk2.'</a></td>';
    	    $stTemp .= '<td align="center">'.$no_reg2.'</td>';
	    if($_COOKIE["ck_cc2"]=="on" | $_COOKIE["ck_cc2"]=="")
		    $stTemp .= '<td align="center">'.$nama_prop.'</td>';
	    if($_COOKIE["ck_cc3"]=="on" | $_COOKIE["ck_cc3"]=="")
		    $stTemp .= '<td align="center">'.$nama_kab.'</td>';
	    if($_COOKIE["ck_cc4"]=="on" | $_COOKIE["ck_cc4"]=="")
		    $stTemp .= '<td align="center">'.$jenis_kk.'</td>';
	    if($_COOKIE["ck_cc5"]=="on" | $_COOKIE["ck_cc5"]=="")
		    $stTemp .= '<td align="center">'.$kecamatan2.'</td>';
	    if($_COOKIE["ck_cc6"]=="on" | $_COOKIE["ck_cc6"]=="")
		    $stTemp .= '<td align="center">'.$jumlah_anggota.'</td>';
	    if($_COOKIE["ck_cc7"]=="on" | $_COOKIE["ck_cc7"]=="")
		    $stTemp .= '<td align="center">'.$hp.'</td>';
	    if($_COOKIE["ck_cc8"]=="on" | $_COOKIE["ck_cc8"]=="")
		    $stTemp .= '<td align="center">'.'<a href="https://mail.google.com/mail/?view=cm&tf=0&to='.$email.'&fs=1&shva=1" target="_blank">'.$email.'</a>'.'</td>';
	    if($_COOKIE["ck_cc9"]=="on" | $_COOKIE["ck_cc9"]=="")
		    $stTemp .= '<td align="center">'.$nama_bank.'</td>';
	    if($_COOKIE["ck_cc10"]=="on" | $_COOKIE["ck_cc10"]=="")
		    $stTemp .= '<td align="center">'.$no_rek_bank.'</td>';
	    if($_COOKIE["ck_cc11"]=="on" | $_COOKIE["ck_cc11"]=="")
		    $stTemp .= '<td align="center">'.$rek_atas_nama.'</td>';
	    $urut=$urut+1;
	    echo $sTemp;
	    $sTemp='';
	}
	if ($no_reg2=='')
	{
	    $stTemp .= '</tr><tr><td align="center"> Data tidak ditemukan</td>';
	    $stTemp .= '<td align="center"> </td>';
	    if($_COOKIE["ck_cc2"]=="on" | $_COOKIE["ck_cc2"]=="")
		    $stTemp .= '<td align="center"> </td>';
	    if($_COOKIE["ck_cc3"]=="on" | $_COOKIE["ck_cc3"]=="")
		    $stTemp .= '<td align="center"> </td>';
	    if($_COOKIE["ck_cc4"]=="on" | $_COOKIE["ck_cc4"]=="")
		    $stTemp .= '<td align="center"> </td>';
	    if($_COOKIE["ck_cc5"]=="on" | $_COOKIE["ck_cc5"]=="")
		    $stTemp .= '<td align="center"> </td>';
	    if($_COOKIE["ck_cc6"]=="on" | $_COOKIE["ck_cc6"]=="")
		    $stTemp .= '<td align="center"> </td>';
	    if($_COOKIE["ck_cc7"]=="on" | $_COOKIE["ck_cc7"]=="")
		    $stTemp .= '<td align="center"> </td>';
	    if($_COOKIE["ck_cc8"]=="on" | $_COOKIE["ck_cc8"]=="")
		    $stTemp .= '<td align="center"> </td>';
	    if($_COOKIE["ck_cc9"]=="on" | $_COOKIE["ck_cc9"]=="")
		    $stTemp .= '<td align="center"> </td>';
	    if($_COOKIE["ck_cc10"]=="on" | $_COOKIE["ck_cc10"]=="")
		    $stTemp .= '<td align="center"> </td>';
	    if($_COOKIE["ck_cc11"]=="on" | $_COOKIE["ck_cc11"]=="")
		    $stTemp .= '<td align="center"> </td>';
	}
	$stTemp .= '</table>';
	echo    $stTemp;
  }
?>
